Java for Beginners: by Knowledge flow
Author:Knowledge flow [flow, Knowledge]
Language: eng
Format: epub
Publisher: Knowledge flow
Published: 2015-03-08T22:00:00+00:00
Control Statements
There three types of statements in java.
Selection statements
Iteration statements
Jump statements
Selection statements
It is to manage the flow of programs that is to be executed based on the dynamic conditions which can be only realized during the run time.
It provides flexibility.
If statement- It provides different paths for execution of program.
Syntax
If (condition provided) statement a;
Else
Statement b;
This means if the condition is true, then statement a is executed but if false then statement b is executed.
For example
int a, b;
If (x < y) a=0;
Else
b=0;
Now there is one type of procedure using if statement i.e. nested if statement and it is very common method in programming world.
For example
If (a == 10) {
If (b < 15) i = j;
If (c > 50) p = q;
Else
i = p;
}
Else
i = q;
Now, the second if statement in the parenthesis is associated with else. Another type of procedure is of using if statement is the if-else-if ladder statement.
For example
If (condition)
Statement;
Else if (condition)
Statement;
Else if (condition)
Statement;
.
.
.
.
.
Else
Statement;
Switch statements
It is a multi branched statement.
Syntax
Switch (expression)
{
Case value 1:
Statement
Break;
Case value 2:
Statement
Break;
.
.
.
Case vale n:
Statement
Break;
Default:
Statement;
}
The functioning of the switch statement is compares the given value with all the cases and when the match found the program sequence is executed.
For example
Class sampswitch {
Public static void main (string args [])
{
Switch (i)
{
Case0:
System.out.println (“i is zero.”);
Break;
Case1:
System.out.println(“i is one.”)
Break;
Default:
System.out.println (“i is greater than 4.”)
}
Output
i is zero.
i is one.
i is greater than 4.
i is greater than 4.
Example of nested switch loop program
Switch (countfigures)
{
Case 1:
Switch (targetvalue)
{//nested switch//
Case 0:
System.out.println (“target is zero”;
Break;
Case 1:
System.out.println (“target is one”;
Break;
}
Break;
Case 2: //...
Important features of switch statement are.
Switch statement can only check for equality unlike if.
There cannot be two cases constant in the same switch with identical values.
It is more effective than using the set of nested if statement.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Deep Learning with Python by François Chollet(14836)
The Mikado Method by Ola Ellnestam Daniel Brolund(12087)
Hello! Python by Anthony Briggs(12000)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(11398)
Dependency Injection in .NET by Mark Seemann(11178)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10528)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(10001)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(9621)
Grails in Action by Glen Smith Peter Ledbrook(9321)
Hit Refresh by Satya Nadella(9039)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(8926)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(8816)
The Kubernetes Operator Framework Book by Michael Dame(8473)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(8376)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8295)
Robo-Advisor with Python by Aki Ranin(8248)
Practical Computer Architecture with Python and ARM by Alan Clements(8223)
Implementing Enterprise Observability for Success by Manisha Agrawal and Karun Krishnannair(8193)
Building Low Latency Applications with C++ by Sourav Ghosh(8097)